package com.boang.common;

import com.boang.exception.MyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理 ServiceException 异常
     */
    @ResponseBody
    @ExceptionHandler(value = MyException.class)
    public Result<Void> serviceExceptionHandler(MyException ex) {
    	log.error("出现服务异常",ex);
        // 包装 Result 结果
        Result<Void> Result = new Result<>();
        Result.setCode(ex.getCode());
        Result.setMessage(ex.getMessage());
        return Result;
    }

}